import utils.readFileUtils.excel_control
import pandas as pd
import openpyxl
from common.baserequest import Base_request

# excl_list = utils.readFileUtils.excel_control.read_excel_data('sheet1', f'C:\\Users\\guohan\\Desktop\\gh.xlsx')

def get_ProductDesc():

    # 读取Excel文件
    df = pd.read_excel('C:\\Users\\guohan\\Desktop\\Des.xlsx', sheet_name='Sheet1')
    excel_file = openpyxl.load_workbook('C:\\Users\\guohan\\Desktop\\Des.xlsx')
    excel_sheet = excel_file['Sheet1']

    # 读取特定列数据
    sku_list = list(df['sku'])

    erp = Base_request()  # D:\zhcx-service-test\common\baserequest.py
    url = 'http://apiep.zhcxkj.com/ProductEdit/GetProductEditInfo'
    user = "irobotbox"
    pwd = "i1r5o8Botbox"
    for i, row in enumerate(sku_list):
        data = {
                "input": {
                "CustomerID": 1,
                "SKU": [str(row)],
                "EditStatus": 1
                }
                }

        res = erp.post_auth(url=url, data=data, user=user, pwd=pwd)
        result = res.get('data')[0].get('ProductDetail')
        for d in result:
            languageType = d.get('languageType')
            # productDesc = []
            if languageType == 'EN':
                excel_sheet.cell(row=i+2, column=3).value = d.get('productDesc')
                # productDesc.append(i.get('productDesc'))
            else:
                continue
            # excel_sheet.cell(row=2, column=3).value = productDesc
        excel_file.save('C:\\Users\\guohan\\Desktop\\Des.xlsx')

get_ProductDesc()
